/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author antonio
 */
@Entity
@Table(name = "Storage")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Storage.findAll", query = "SELECT s FROM Storage s"),
    @NamedQuery(name = "Storage.findByPlayer", query = "SELECT s FROM Storage s WHERE s.storagePK.player = :player"),
    @NamedQuery(name = "Storage.findByResource", query = "SELECT s FROM Storage s WHERE s.storagePK.resource = :resource"),
    @NamedQuery(name = "Storage.findByAmount", query = "SELECT s FROM Storage s WHERE s.amount = :amount")})
public class Storage implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected StoragePK storagePK;
    @Column(name = "amount")
    private Integer amount;
    @JoinColumn(name = "resource", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Resource resource1;
    @JoinColumn(name = "player", referencedColumnName = "username", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Player player1;

    public Storage() {
    }

    public Storage(StoragePK storagePK) {
        this.storagePK = storagePK;
    }

    public Storage(String player, int resource) {
        this.storagePK = new StoragePK(player, resource);
    }

    public StoragePK getStoragePK() {
        return storagePK;
    }

    public void setStoragePK(StoragePK storagePK) {
        this.storagePK = storagePK;
    }

    public Integer getAmount() {
        return amount;
    }

    public void setAmount(Integer amount) {
        this.amount = amount;
    }

    public Resource getResource1() {
        return resource1;
    }

    public void setResource1(Resource resource1) {
        this.resource1 = resource1;
    }

    public Player getPlayer1() {
        return player1;
    }

    public void setPlayer1(Player player1) {
        this.player1 = player1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (storagePK != null ? storagePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Storage)) {
            return false;
        }
        Storage other = (Storage) object;
        if ((this.storagePK == null && other.storagePK != null) || (this.storagePK != null && !this.storagePK.equals(other.storagePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Storage[ storagePK=" + storagePK + " ]";
    }
    
}
